import Vue from 'vue'
import VueRouter from 'vue-router'
import Index from '../views/Index.vue'
import Home from '../views/Home.vue'

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Home',
    redirect: '/index',
    component: Home,
    children: [
      {
        path: '/index',
        name: 'index',
        component: Index
      },
      {
        path: '/product/:id',
        name: 'Product',
        component: () => import('../views/Product.vue')
      },
      {
        path: '/cart',
        name: 'Cart',
        component: () => import('../views/Cart.vue')
      },
      {
        path: '/order/checkout',
        name: 'OrderCheck',
        component: () => import('../views/OrderCheck.vue')
      },
      {
        path: '/pay/:id',
        name: 'Pay',
        component: () => import('../views/Pay.vue')
      },
      {
        path: '/deebot-list',
        name: 'deebotList',
        component: () => import('../views/deebotList.vue')
      },
      {
        path: '/winbot-list',
        name: 'winbotList',
        component: () => import('../views/winbotList.vue')
      },
      {
        path: '/atmbot-list',
        name: 'atmbotList',
        component: () => import('../views/atmbotList.vue')
      },
      {
        path: '/peijian-list',
        name: 'peijianList',
        component: () => import('../views/peijianList.vue')
      },
      {
        path: '/search',
        name: 'Search',
        component: () => import('../views/Search.vue')
      },

    ]
  },
  {
    path: '/order',
    name: 'OrderList',
    component: () => import('../views/OrderList.vue'),
    children: [
      {
        path: '/order/detail/:id',
        name: 'orderDetail',
        component: () => import('../views/orderDetail.vue')
      },
    ]
  },
  // {
  //   path: '/orderDetail',
  //   name: 'orderDetail',
  //   component: () => import('../views/orderDetail.vue')
  // },
  {
    path: '/member',
    name: 'Member',
    component: () => import('../views/Member.vue')
  },
  {
    path: '/vip',
    name: 'Vip',
    redirect: '/vip/index',
    component: () => import('../views/Vip.vue'),
    children: [
      {
        path: '/vip/index',
        name: 'VipIndex',
        component: () => import('../views/VipIndex.vue')
      },
      {
        path: '/vip/intergral',
        name: 'VipIntergral',
        component: () => import('../views/VipIntergral.vue')
      },
      {
        path: '/vip/member-grow',
        name: 'MemberGrow',
        component: () => import('../views/MemberGrow.vue')
      },
    ]
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('../views/Login.vue')
  },
  {
    path: '/register',
    name: 'Register',
    component: () => import('../views/Register.vue')
  },
  {
    path: '/forget',
    name: 'Forget',
    component: () => import('../views/ForgetPassword.vue')
  },
  {
    path: '/huanxin',
    name: 'HuanXin',
    component: () => import('../views/HuanXin.vue')
  },
]

const router = new VueRouter({
  routes
})
router.beforeEach((to, from, next) => {
  window.scrollTo(0, 0);
  next();
})

export default router
